<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
markan.ServerLiveCheck serverLiveCheck = new markan.ServerLiveCheck();
markan.PostSubmit postSubmit = new markan.PostSubmit();
java.text.SimpleDateFormat dateFormat =  new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String programName = "[서버 상태 체크 프로그램]\n";
//String groupId = "186577728129797";
String groupId = "319611651466850";

String access_token = (String) application.getAttribute("access_token");
if (access_token==null)
	response.sendRedirect("index.jsp");

String portal_korea = "";
String portal_english = "";
String portal_mobile = ""; 

if(serverLiveCheck.checkServer("https://www.renewableenergy.or.kr/main.do")==200) {
	portal_korea = "서버 살아있음.";
	application.setAttribute("portal_korea", 1);
} else {
	
	portal_korea = "삼가 국문서버의 명복을 빕니다.";
	
	//페이스북 알림 
	if( ((Integer) application.getAttribute("portal_korea")) == 1) {
		application.setAttribute("portal_korea", 0);
		if (access_token!=null)
			postSubmit.send("https://graph.facebook.com/"+groupId+"/feed?access_token=" + access_token, programName + portal_korea);
	}
}

if(serverLiveCheck.checkServer("http://www.renewableenergy-korea.com/main.do")==200) {
	portal_english = "서버 살아있음.";
	application.setAttribute("portal_english", 1);
} else {
	
	portal_english = "삼가 영문서버의 명복을 빕니다.";
	
	//페이스북 알림 
	if( ((Integer) application.getAttribute("portal_english")) == 1) {
		application.setAttribute("portal_english", 0);
		if (access_token!=null)
			postSubmit.send("https://graph.facebook.com/"+groupId+"/feed?access_token=" + access_token, programName + portal_english);
	}
}
  
if(serverLiveCheck.checkServer("http://m.renewableenergy.or.kr/main.do")==200) {
	portal_mobile = "서버 살아있음.";
	application.setAttribute("portal_mobile", 1);
} else {
	portal_mobile = "삼가 모바일서버의 명복을 빕니다.";
	
	//페이스북 알림 
	if( ((Integer) application.getAttribute("portal_mobile")) == 1) {
		application.setAttribute("portal_mobile", 0);
		if (access_token!=null)
			postSubmit.send("https://graph.facebook.com/"+groupId+"/feed?access_token=" + access_token, programName + portal_mobile);
	}
	 
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>서버 상태</title>
<script>
  	var tid = setInterval("location.reload(true)", 1000*5);
</script>
</head> 
<body>
<table border=1>
<tr><th>국문</th><td><%=portal_korea %></td></tr>
<tr><th>영문</th><td><%=portal_english %></td></tr>
<tr><th>모바일</th><td><%=portal_mobile %></td></tr>
<tr><th>체크시간</th><td><%=dateFormat.format(new java.util.Date())%></td></tr>
</table>
</body>
</html>